package Ed;

import java.awt.Color;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Portatil
 */
public class Txt extends javax.swing.JFrame {

    static Image ico;
    int neg = 0, cur = 0, tamañox = 13;
    Color colores;
    String familiact = "Monoespaced";
    File fichero;
    boolean buscar1;
    int intpalabra, intpalabraaux;
    String palabrab, texto;

    /**
     * Creates new form Txt
     */
    public Txt() {
        initComponents();
        setSize(800, 600);
        setLocationRelativeTo(null);
        setTitle("Editor de Textos ACME");
        icono();
        setIconImage(ico);
        buscardi.setSize(300, 150);
        jDialog1.setSize(200, 120);
    }

    private void icono() {
        URL pathIcon = this.getClass().getClassLoader().getResource("img/icono.png");
        Toolkit kit = Toolkit.getDefaultToolkit();
        ico = kit.createImage(pathIcon);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        buscardi = new javax.swing.JDialog();
        jTextField2 = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jPopupMenu1 = new javax.swing.JPopupMenu();
        copiar1 = new javax.swing.JMenuItem();
        cortar1 = new javax.swing.JMenuItem();
        pegar1 = new javax.swing.JMenuItem();
        jSeparator7 = new javax.swing.JPopupMenu.Separator();
        bus1 = new javax.swing.JMenuItem();
        jSeparator8 = new javax.swing.JPopupMenu.Separator();
        selto1 = new javax.swing.JMenuItem();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jToolBar1 = new javax.swing.JToolBar();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jSeparator6 = new javax.swing.JToolBar.Separator();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        archivo = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        salvar = new javax.swing.JMenuItem();
        abrir = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        salir = new javax.swing.JMenuItem();
        editar = new javax.swing.JMenu();
        copiar = new javax.swing.JMenuItem();
        cortar = new javax.swing.JMenuItem();
        pegar = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JPopupMenu.Separator();
        bus = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        selto = new javax.swing.JMenuItem();
        formato = new javax.swing.JMenu();
        estilo = new javax.swing.JMenu();
        negrita = new javax.swing.JMenuItem();
        cursiva = new javax.swing.JMenuItem();
        familia = new javax.swing.JMenu();
        arial = new javax.swing.JMenuItem();
        comic = new javax.swing.JMenuItem();
        monoespaced = new javax.swing.JMenuItem();
        times = new javax.swing.JMenuItem();
        tamaño = new javax.swing.JMenu();
        ocho = new javax.swing.JMenuItem();
        once = new javax.swing.JMenuItem();
        trece = new javax.swing.JMenuItem();
        ven = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
        pers = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        color = new javax.swing.JMenu();
        fuente = new javax.swing.JMenuItem();
        fondo = new javax.swing.JMenuItem();

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        buscardi.setResizable(false);

        jTextField2.setForeground(new java.awt.Color(102, 102, 102));
        jTextField2.setText("Buscar...");
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });
        jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextField2FocusGained(evt);
            }
        });

        jButton6.setText("Buscar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Siguiente");
        jButton7.setEnabled(false);
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Cancelar");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setText("Atrás");
        jButton9.setEnabled(false);
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout buscardiLayout = new javax.swing.GroupLayout(buscardi.getContentPane());
        buscardi.getContentPane().setLayout(buscardiLayout);
        buscardiLayout.setHorizontalGroup(
            buscardiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buscardiLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(buscardiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField2)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buscardiLayout.createSequentialGroup()
                        .addGap(0, 67, Short.MAX_VALUE)
                        .addGroup(buscardiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton8, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buscardiLayout.createSequentialGroup()
                                .addComponent(jButton9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton7)))))
                .addContainerGap())
        );
        buscardiLayout.setVerticalGroup(
            buscardiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buscardiLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(buscardiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton6)
                    .addComponent(jButton7)
                    .addComponent(jButton9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton8)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        copiar1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        copiar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/copyp.png"))); // NOI18N
        copiar1.setText("Copiar");
        copiar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copiar1ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(copiar1);

        cortar1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        cortar1.setText("Cortar");
        cortar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cortar1ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(cortar1);

        pegar1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        pegar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/pegarp.png"))); // NOI18N
        pegar1.setText("Pegar");
        pegar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pegar1ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(pegar1);
        jPopupMenu1.add(jSeparator7);

        bus1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
        bus1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/buscarp.png"))); // NOI18N
        bus1.setText("Buscar");
        bus1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bus1ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(bus1);
        jPopupMenu1.add(jSeparator8);

        selto1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        selto1.setText("Seleccionar todo");
        selto1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selto1ActionPerformed(evt);
            }
        });
        jPopupMenu1.add(selto1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextArea1.setColumns(20);
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setWrapStyleWord(true);
        jScrollPane1.setViewportView(jTextArea1);

        jToolBar1.setRollover(true);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/nuevo.png"))); // NOI18N
        jButton3.setBorder(null);
        jButton3.setBorderPainted(false);
        jButton3.setContentAreaFilled(false);
        jButton3.setDefaultCapable(false);
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton3);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/copy.png"))); // NOI18N
        jButton2.setBorder(null);
        jButton2.setBorderPainted(false);
        jButton2.setContentAreaFilled(false);
        jButton2.setDefaultCapable(false);
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/pegar.png"))); // NOI18N
        jButton4.setBorder(null);
        jButton4.setBorderPainted(false);
        jButton4.setContentAreaFilled(false);
        jButton4.setDefaultCapable(false);
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton4);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/imprimir.png"))); // NOI18N
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton5);

        jSeparator6.setMinimumSize(new java.awt.Dimension(20, 0));
        jToolBar1.add(jSeparator6);

        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/guardar.png"))); // NOI18N
        jButton10.setFocusable(false);
        jButton10.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton10.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton10);

        jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/buscar.png"))); // NOI18N
        jButton11.setFocusable(false);
        jButton11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton11.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton11);

        archivo.setText("Archivo");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/nuevop.png"))); // NOI18N
        jMenuItem1.setText("Nuevo");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        archivo.add(jMenuItem1);

        salvar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/guardarp.png"))); // NOI18N
        salvar.setText("Guardar");
        salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarActionPerformed(evt);
            }
        });
        archivo.add(salvar);

        abrir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        abrir.setText("Abrir");
        abrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abrirActionPerformed(evt);
            }
        });
        archivo.add(abrir);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/imprimirp.png"))); // NOI18N
        jMenuItem2.setText("Imprimir");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        archivo.add(jMenuItem2);
        archivo.add(jSeparator3);

        salir.setText("Salir");
        salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirActionPerformed(evt);
            }
        });
        archivo.add(salir);

        jMenuBar1.add(archivo);

        editar.setText("Editar");

        copiar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        copiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/copyp.png"))); // NOI18N
        copiar.setText("Copiar");
        copiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copiarActionPerformed(evt);
            }
        });
        editar.add(copiar);

        cortar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        cortar.setText("Cortar");
        cortar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cortarActionPerformed(evt);
            }
        });
        editar.add(cortar);

        pegar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        pegar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/pegarp.png"))); // NOI18N
        pegar.setText("Pegar");
        pegar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pegarActionPerformed(evt);
            }
        });
        editar.add(pegar);
        editar.add(jSeparator5);

        bus.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
        bus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/buscarp.png"))); // NOI18N
        bus.setText("Buscar");
        bus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                busActionPerformed(evt);
            }
        });
        editar.add(bus);
        editar.add(jSeparator1);

        selto.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        selto.setText("Seleccionar todo");
        selto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seltoActionPerformed(evt);
            }
        });
        editar.add(selto);

        jMenuBar1.add(editar);

        formato.setText("Formato");

        estilo.setText("Estilo");

        negrita.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        negrita.setText("Negrita");
        negrita.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                negritaActionPerformed(evt);
            }
        });
        estilo.add(negrita);

        cursiva.setText("Cursiva");
        cursiva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cursivaActionPerformed(evt);
            }
        });
        estilo.add(cursiva);

        formato.add(estilo);

        familia.setText("Familia");

        arial.setText("Arial");
        arial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                arialActionPerformed(evt);
            }
        });
        familia.add(arial);

        comic.setText("Comic Sans");
        comic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comicActionPerformed(evt);
            }
        });
        familia.add(comic);

        monoespaced.setText("Monoespaced");
        monoespaced.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monoespacedActionPerformed(evt);
            }
        });
        familia.add(monoespaced);

        times.setText("Times New Roman");
        times.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                timesActionPerformed(evt);
            }
        });
        familia.add(times);

        formato.add(familia);

        tamaño.setText("Tamaño");

        ocho.setText("8");
        ocho.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ochoActionPerformed(evt);
            }
        });
        tamaño.add(ocho);

        once.setText("11");
        once.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onceActionPerformed(evt);
            }
        });
        tamaño.add(once);

        trece.setText("13");
        trece.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                treceActionPerformed(evt);
            }
        });
        tamaño.add(trece);

        ven.setText("20");
        ven.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                venActionPerformed(evt);
            }
        });
        tamaño.add(ven);
        tamaño.add(jSeparator4);

        pers.setText("Personalizado");
        pers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                persActionPerformed(evt);
            }
        });
        tamaño.add(pers);

        formato.add(tamaño);
        formato.add(jSeparator2);

        color.setText("Color");

        fuente.setText("Fuente");
        fuente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fuenteActionPerformed(evt);
            }
        });
        color.add(fuente);

        fondo.setText("Fondo");
        fondo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fondoActionPerformed(evt);
            }
        });
        color.add(fondo);

        formato.add(color);

        jMenuBar1.add(formato);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void pegarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pegarActionPerformed
        // TODO add your handling code here:
        jTextArea1.paste();
    }//GEN-LAST:event_pegarActionPerformed

    private void copiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copiarActionPerformed
        // TODO add your handling code here:
        jTextArea1.copy();
    }//GEN-LAST:event_copiarActionPerformed

    private void cortarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cortarActionPerformed
        // TODO add your handling code here:
        jTextArea1.cut();
    }//GEN-LAST:event_cortarActionPerformed

    private void negritaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_negritaActionPerformed
        // TODO add your handling code here:
        if (neg != Font.BOLD) {
            neg = Font.BOLD;
        } else {
            neg = 0;
        }
        familia();
    }//GEN-LAST:event_negritaActionPerformed

    private void cursivaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cursivaActionPerformed
        // TODO add your handling code here:
        if (cur != Font.ITALIC) {
            cur = Font.ITALIC;
        } else {
            cur = 0;
        }
        familia();
    }//GEN-LAST:event_cursivaActionPerformed

    private void seltoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seltoActionPerformed
        // TODO add your handling code here:
        jTextArea1.selectAll();
    }//GEN-LAST:event_seltoActionPerformed

    private void arialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_arialActionPerformed
        // TODO add your handling code here:
        familiact = "Arial";
        familia();
    }//GEN-LAST:event_arialActionPerformed

    private void comicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comicActionPerformed
        // TODO add your handling code here:
        familiact = "Comic Sans MS";
        familia();
    }//GEN-LAST:event_comicActionPerformed

    private void monoespacedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monoespacedActionPerformed
        // TODO add your handling code here:
        familiact = "Monoespaced";
        familia();
    }//GEN-LAST:event_monoespacedActionPerformed

    private void timesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timesActionPerformed
        // TODO add your handling code here:
        familiact = "Times New Roman";
        familia();
    }//GEN-LAST:event_timesActionPerformed

    private void fuenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fuenteActionPerformed
        // TODO add your handling code here:
        colores = JColorChooser.showDialog(null, "Seleccionar Color", colores);
        jTextArea1.setForeground(colores);
    }//GEN-LAST:event_fuenteActionPerformed

    private void fondoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fondoActionPerformed
        // TODO add your handling code here:
        colores = JColorChooser.showDialog(null, "Seleccionar Color", colores);
        jTextArea1.setBackground(colores);
    }//GEN-LAST:event_fondoActionPerformed

    private void abrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abrirActionPerformed
        // TODO add your handling code here:
        JFileChooser f = new JFileChooser();
        f.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        int opcion = f.showOpenDialog(null);
        if (opcion == JFileChooser.APPROVE_OPTION) {
            fichero = f.getSelectedFile();
            try {
                abrir(fichero);
            } catch (IOException ex) {
                Logger.getLogger(Txt.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_abrirActionPerformed

    private void salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarActionPerformed
        guardar();
    }//GEN-LAST:event_salvarActionPerformed

    private void salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirActionPerformed
        // TODO add your handling code here:
        System.exit(ABORT);
    }//GEN-LAST:event_salirActionPerformed

    private void persActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_persActionPerformed
        // TODO add your handling code here:
        jDialog1.setLocationRelativeTo(null);
        jDialog1.setTitle("Tamaño");
        jDialog1.setIconImage(ico);
        jDialog1.setVisible(true);
    }//GEN-LAST:event_persActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        int tam;
        try {
            tam = Integer.parseInt(jTextField1.getText());
            tamañox = tam;
            familia();
            jDialog1.setVisible(false);
        } catch (NumberFormatException a) {
            JOptionPane.showMessageDialog(null, "Error con el numero", "Error", JOptionPane.QUESTION_MESSAGE, null);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void ochoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ochoActionPerformed
        // TODO add your handling code here:
        tamañox = 8;
        familia();
    }//GEN-LAST:event_ochoActionPerformed

    private void onceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onceActionPerformed
        // TODO add your handling code here:
        tamañox = 11;
        familia();
    }//GEN-LAST:event_onceActionPerformed

    private void treceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_treceActionPerformed
        // TODO add your handling code here:
        tamañox = 13;
        familia();
    }//GEN-LAST:event_treceActionPerformed

    private void venActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_venActionPerformed
        // TODO add your handling code here:
        tamañox = 20;
        familia();
    }//GEN-LAST:event_venActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        jTextArea1.selectAll();
        jTextArea1.copy();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        nuevo();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        jTextArea1.paste();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        imprimir();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jTextField2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField2FocusGained
        // TODO add your handling code here:
        if (this.buscar1) {
            jTextField2.setText("");
            this.buscar1 = false;
            jTextField2.setForeground(Color.BLACK);
        }
    }//GEN-LAST:event_jTextField2FocusGained

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        palabrab = jTextField2.getText();
        texto = jTextArea1.getText();
        intpalabra = texto.indexOf(palabrab);
        if (intpalabra != -1) {
            jTextArea1.select(intpalabra, intpalabra + palabrab.length());
            jButton7.setEnabled(true);
            jButton9.setEnabled(true);
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
        intpalabraaux = intpalabra;
        intpalabra = texto.indexOf(palabrab, intpalabraaux + 1);
        if (intpalabra != -1) {
            jTextArea1.select(intpalabra, intpalabra + palabrab.length());
        } else {
            intpalabra = texto.indexOf(palabrab);
            if (intpalabra != -1) {
                jTextArea1.select(intpalabra, intpalabra + palabrab.length());
            }
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here:
        buscardi.setVisible(false);
            jButton7.setEnabled(false);
            jButton9.setEnabled(false);
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        // TODO add your handling code here:
        intpalabraaux = intpalabra;
        intpalabra = texto.lastIndexOf(palabrab, intpalabraaux - 1);
        if (intpalabra != -1) {
            jTextArea1.select(intpalabra, intpalabra + palabrab.length());
        } else {
            intpalabra = texto.lastIndexOf(palabrab, jTextArea1.getText().length());
            if (intpalabra != -1) {
                jTextArea1.select(intpalabra, intpalabra + palabrab.length());
            }
        }
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        guardar();
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        // TODO add your handling code here:
        buscar();
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        nuevo();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        imprimir();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void busActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_busActionPerformed
        buscar();
    }//GEN-LAST:event_busActionPerformed

    private void copiar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copiar1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_copiar1ActionPerformed

    private void cortar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cortar1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cortar1ActionPerformed

    private void pegar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pegar1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pegar1ActionPerformed

    private void bus1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bus1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bus1ActionPerformed

    private void selto1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selto1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_selto1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public void grabar(File fichero) throws IOException {
        FileWriter fw;
        String s = jTextArea1.getText();
        fw = new FileWriter(fichero);
        fw.write(s);
        fw.close();
    }

    public void abrir(File fichero) throws IOException {
        jTextArea1.setText("");
        FileReader fr;
        BufferedReader br;
        String linea;
        fr = new FileReader(fichero);
        br = new BufferedReader(fr);
        while ((linea = br.readLine()) != null) {
            jTextArea1.append(linea);
            jTextArea1.append("\n");
        }
        br.close();
        fr.close();
    }

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Txt.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Txt.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Txt.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Txt.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Txt().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem abrir;
    private javax.swing.JMenu archivo;
    private javax.swing.JMenuItem arial;
    private javax.swing.JMenuItem bus;
    private javax.swing.JMenuItem bus1;
    private javax.swing.JDialog buscardi;
    private javax.swing.JMenu color;
    private javax.swing.JMenuItem comic;
    private javax.swing.JMenuItem copiar;
    private javax.swing.JMenuItem copiar1;
    private javax.swing.JMenuItem cortar;
    private javax.swing.JMenuItem cortar1;
    private javax.swing.JMenuItem cursiva;
    private javax.swing.JMenu editar;
    private javax.swing.JMenu estilo;
    private javax.swing.JMenu familia;
    private javax.swing.JMenuItem fondo;
    private javax.swing.JMenu formato;
    private javax.swing.JMenuItem fuente;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JPopupMenu.Separator jSeparator4;
    private javax.swing.JPopupMenu.Separator jSeparator5;
    private javax.swing.JToolBar.Separator jSeparator6;
    private javax.swing.JPopupMenu.Separator jSeparator7;
    private javax.swing.JPopupMenu.Separator jSeparator8;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuItem monoespaced;
    private javax.swing.JMenuItem negrita;
    private javax.swing.JMenuItem ocho;
    private javax.swing.JMenuItem once;
    private javax.swing.JMenuItem pegar;
    private javax.swing.JMenuItem pegar1;
    private javax.swing.JMenuItem pers;
    private javax.swing.JMenuItem salir;
    private javax.swing.JMenuItem salvar;
    private javax.swing.JMenuItem selto;
    private javax.swing.JMenuItem selto1;
    private javax.swing.JMenu tamaño;
    private javax.swing.JMenuItem times;
    private javax.swing.JMenuItem trece;
    private javax.swing.JMenuItem ven;
    // End of variables declaration//GEN-END:variables

    private void familia() {
        Font familiaact;
        familiaact = new Font(familiact, neg + cur, tamañox);
        jTextArea1.setFont(familiaact);
    }

    private void guardar() throws HeadlessException {
        // TODO add your handling code here:JFileChooser f=new JFileChooser();
        JFileChooser f = new JFileChooser();
        f.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        int opcion = f.showSaveDialog(null);
        if (opcion == JFileChooser.APPROVE_OPTION) {
            fichero = f.getSelectedFile();
            try {
                grabar(fichero);
            } catch (IOException ex) {
                Logger.getLogger(Txt.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private void buscar() {
        // TODO add your handling code here:
        buscardi.setLocationRelativeTo(null);
        buscardi.setTitle("Buscar...");
        buscardi.setIconImage(ico);
        buscardi.setVisible(true);
        this.buscar1 = true;
    }

    private void nuevo() throws HeadlessException {
        // TODO add your handling code here:
        int x=JOptionPane.showConfirmDialog(this, "¿Quieres guardar antes de comenzar un texto nuevo?","Nuevo", JOptionPane.YES_NO_OPTION);
        if(x==0){
            guardar();
        }
        jTextArea1.setText("");
        jTextArea1.requestFocus();
    }

    private void imprimir() {
        // TODO add your handling code here:
        Font fuente = new Font(familiact, neg + cur, tamañox);
        Impresora imp = new Impresora(fuente);
        imp.imprimir(jTextArea1.getText());
    }
}
